import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

///3D效果变换
///指针已接触屏幕并可能开始移动。
///onPanDown: (details) {},
/// 指针已经接触屏幕并开始移动。
/// onPanStart: (details) {},
///与屏幕接触并移动的指针再次移动。
/// onPanUpdate: (details) {},
///先前与屏幕接触并移动的指针不再与屏幕接触，并且当它停止接触屏幕时以特定速度移动。
/// onPanEnd: (details) {},
/// 先前触发 onPanDown 的指针未完成。
/// onPanCancel: () {},
class Transform3DDemo extends StatefulWidget {
  final String? text;

  Transform3DDemo({this.text}) : super();

  @override
  State<StatefulWidget> createState() {
    return _Transform3DState();
  }
}

class _Transform3DState extends State<Transform3DDemo> {
  double _rotateX = 0.0;
  double _rotateY = 0.0;

  @override
  Widget build(BuildContext context) {
    return Transform(
      transform: Matrix4.identity()
        ..setEntry(3, 2, 0.001)
        ..rotateX(_rotateX)
        ..rotateY(_rotateY),
      child: Scaffold(
        appBar: AppBar(
          title: Text(widget.text ?? ""),
        ),
        body: GestureDetector(
          onPanUpdate: (details) {
            //不断更新
            setState(() {
              _rotateX += details.delta.dy * .005;
              _rotateY += details.delta.dx * -.005;
            });
          },
          child: Container(
            alignment: Alignment.center,
            color: Colors.white,
            child: Text("3D变换demo"),
          ),
        ),
      ),
    );
  }
}
